package 数组;

import java.util.ArrayList;
import java.util.List;

/**
 * https://leetcode.cn/problems/find-all-numbers-disappeared-in-an-array/
 *
 * 题解：https://leetcode.cn/problems/find-all-numbers-disappeared-in-an-array/solutions/601946/zhao-dao-suo-you-shu-zu-zhong-xiao-shi-d-mabl/
 */
public class _448_找到所有数组中消失的数字 {

    /**
     * 题解：https://leetcode.cn/problems/find-all-numbers-disappeared-in-an-array/solutions/601946/zhao-dao-suo-you-shu-zu-zhong-xiao-shi-d-mabl/
     * @param nums
     * @return
     */
    public List<Integer> findDisappearedNumbers(int[] nums) {
        int[] result = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            // 因为nums数组内的元素都小于nums.length，所以这边%都会落到数组的位置上
            result[nums[i] % nums.length] = 1;
        }

        List<Integer> resultList = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            if (result[i] == 0) {
                resultList.add(i == 0 ? nums.length : i);
            }
        }

        return resultList;
    }
}

